package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.StrategyPersistenceVO;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisRedisService;
import cn.wolfcode.luowowo.cache.util.RedisKeys;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * Created by admin on 2019/8/14.
 */
@Component
public class RedisDataPersistenceJob {
    @Reference
    private IStrategyStatisRedisService strategyStatisRedisService;
    @Reference
    private IStrategyDetailService strategyDetailService;
//    @Scheduled(cron = "0/10 * * * * ?")
    public void redisDataPersistence() {
        System.out.println("-----------------------------");
        List<StrategyStatisVO> vos = strategyStatisRedisService.getStrategyStatisVos(RedisKeys.STRATEGY_STATIS_VO.getPrefix());
        System.out.println(vos);
        StrategyPersistenceVO persistenceVO = new StrategyPersistenceVO();
        for (StrategyStatisVO vo : vos) {
            try {
                BeanUtils.copyProperties(persistenceVO, vo);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
            System.out.println(vo);
            strategyDetailService.updateStatis(persistenceVO);
        }
        System.out.println("====================");
    }
}
